package org.apache.jsp.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.util.ArrayList;
import java.util.Iterator;
import org.pomirkovany.beans.Item;

public final class category_jsp extends org.apache.jasper.runtime.HttpJspBase
    implements org.apache.jasper.runtime.JspSourceDependent {

  private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

  private static java.util.List _jspx_dependants;

  private javax.el.ExpressionFactory _el_expressionfactory;
  private org.apache.AnnotationProcessor _jsp_annotationprocessor;

  public Object getDependants() {
    return _jspx_dependants;
  }

  public void _jspInit() {
    _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
    _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
  }

  public void _jspDestroy() {
  }

  public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    PageContext _jspx_page_context = null;


    try {
      response.setContentType("text/html");
      pageContext = _jspxFactory.getPageContext(this, request, response,
      			null, true, 8192, true);
      _jspx_page_context = pageContext;
      application = pageContext.getServletContext();
      config = pageContext.getServletConfig();
      session = pageContext.getSession();
      out = pageContext.getOut();
      _jspx_out = out;

      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("\r\n");
      org.pomirkovany.model.DataAccess dataAccess = null;
      synchronized (application) {
        dataAccess = (org.pomirkovany.model.DataAccess) _jspx_page_context.getAttribute("dataAccess", PageContext.APPLICATION_SCOPE);
        if (dataAccess == null){
          dataAccess = new org.pomirkovany.model.DataAccess();
          _jspx_page_context.setAttribute("dataAccess", dataAccess, PageContext.APPLICATION_SCOPE);
        }
      }
      out.write('\r');
      out.write('\n');
 String base = (String)application.getAttribute("base");
String imageURL = (String)application.getAttribute("imageURL");

      out.write("\r\n");
      out.write("<html>\r\n");
      out.write("<head>\r\n");
      out.write("  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\r\n");
      out.write("  <title>Browse Catalog</title>\r\n");
      out.write("  <link rel=\"stylesheet\" href=\"/Cataloguer/css/cataloguer.css\" type=\"text/css\"/>\r\n");
      out.write("  </head>\r\n");
      out.write("<body>\r\n");
      out.write("\r\n");
      org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "header.jsp", out, true);
      out.write('\r');
      out.write('\n');
      org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "SearchBar.jsp", out, true);
      out.write('\r');
      out.write('\n');
      org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "typesmenu.jsp", out, true);
      out.write('\r');
      out.write('\n');
     
  String categoryId = request.getParameter("id");
  String categoryName = null;
  if (categoryId != null && !categoryId.trim().equals("")) {
    try {
      categoryName = dataAccess.getCategoryName(categoryId);
      }
    catch(NumberFormatException e) {}
    }
	else{
	out.print("<p>Chose a category</p>");	
	}
  if (categoryName != null) {
  
      out.write("\r\n");
      out.write("    <div class=\"content\">\r\n");
      out.write("      <p>Category: <strong>");
      out.print(categoryName);
      out.write("</strong></p>\r\n");
      out.write("      <table>\r\n");
      out.write("        <tr>\r\n");
      out.write("          <th>Name</th>\r\n");
      out.write("          <th>Author</th>\r\n");
      out.write("          <th>Owner</th>\r\n");
      out.write("          <th>Date</th>\r\n");
      out.write("          <th>Borrowed</th>\r\n");
      out.write("          <th>Picture</th>\r\n");
      out.write("          <th>Location</th>\r\n");
      out.write("          <th>Rate</th>\r\n");
      out.write("          </tr>\r\n");
      out.write("          <form action=\"\">\r\n");

        ArrayList items = dataAccess.getItemsInCategory(categoryId);
        Iterator iterator = items.iterator();
        while (iterator.hasNext()) {
          Item item = (Item)iterator.next();
          String pId = item.getId();
  
      out.write("\r\n");
      out.write("          <tr>\r\n");
      out.write("            <td>");
      out.print(item.getName());
      out.write("</td>\r\n");
      out.write("            <td>");
      out.print(item.getAuthor());
      out.write("</td>\r\n");
      out.write("            <td>");
      out.print(item.getOwner());
      out.write("</td>\r\n");
      out.write("            <td>");
      out.print(item.getDate());
      out.write("</td>\r\n");
      out.write("            <td><input type=\"checkbox\" name=\"vehicle\"\r\n");
      out.write("             ");
if(item.isBorrowed()){
      out.write("\r\n");
      out.write("             checked");
}
      out.write(" value=\"\" disabled /></td>\r\n");
      out.write("            <td><img border=\"0\" src=\"");
      out.print(imageURL + item.getPicture());
      out.write("\" alt=\"no picture\" width=\"90%\" height=\"90%\" /></td>\r\n");
      out.write("\r\n");
      out.write("            <td>");
      out.print(item.getLocation());
      out.write("</td>\r\n");
      out.write("            <td><img border=\"0\" src=\"images\\");
      out.print(item.getRate());
      out.write("s.png\" alt=\"no picture\" width=\"90%\" height=\"90%\" /></td>\r\n");
      out.write("                        \r\n");
      out.write("            <td><a class=\"link1\"\r\n");
      out.write("              href=\"");
      out.print(base);
      out.write("?action=itemDetails&itemId=");
      out.print(pId);
      out.write("\">\r\n");
      out.write("              Details</a></td>\r\n");
      out.write("            </tr>\r\n");

          }
  
      out.write("\r\n");
      out.write("  </form>\r\n");
      out.write("  \r\n");
      out.write("        </table>\r\n");
      out.write("      </div>\r\n");

    }
  else {
	
      out.write("<p class=\"error\"></p>");

	}

      out.write("\r\n");
      out.write("</body>\r\n");
      out.write("</html>\r\n");
    } catch (Throwable t) {
      if (!(t instanceof SkipPageException)){
        out = _jspx_out;
        if (out != null && out.getBufferSize() != 0)
          try { out.clearBuffer(); } catch (java.io.IOException e) {}
        if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
      }
    } finally {
      _jspxFactory.releasePageContext(_jspx_page_context);
    }
  }
}
